/*
 * Copyright © 2010 SenseForce.com.
 * The Software shall be used for Good, not Evil.
 */

package com.senseforce.midlets;

import com.senseforce.classes.MyCheckItem;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.ImageItem;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemCommandListener;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.StringItem;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

/**
 * @author jcccn
 * @site http://www.senseforce.com/
 */

public class Start extends MIDlet implements CommandListener, ItemCommandListener {

	private Display display;
        private Form form;
        private MyCheckItem myCheck;

	public Start() {
		// TODO Auto-generated constructor stub
		super();
	}

	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		// TODO Auto-generated method stub

	}

	protected void pauseApp() {
		// TODO Auto-generated method stub

	}

	protected void startApp() throws MIDletStateChangeException {
		// TODO Auto-generated method stub
		display = Display.getDisplay(this);

		Image img = null;
		try {
			img = Image.createImage("/taobao.png");
		}catch (Exception e) {
			System.out.println(e);
		}

//		List list1 = new List("List Test", Choice.IMPLICIT);
//		list1.append("Alibaba", img);
//		list1.append("Tencent", null);
//		list1.append("Baidu", null);
//		list1.setSelectedIndex(0, true);
//		list1.addCommand(new Command("OK", Command.OK, 1));
//		list1.setCommandListener(this);
//		display.setCurrent(list1);

		form = new Form("Form Test");

		StringItem si1 = new StringItem("String", "SenseForce", Item.PLAIN);
		StringItem si2 = new StringItem("Button", "Click!", Item.BUTTON);
		si2.addCommand(new Command("What", Command.SCREEN, 0));
		si2.addCommand(new Command("How", Command.SCREEN, 1));
		si2.setItemCommandListener(this);
		StringItem si3 = new StringItem("HyperLink", "www.senseforce.com", Item.HYPERLINK);
		si3.addCommand(new Command("Click", Command.SCREEN, 0));
		si3.setItemCommandListener(this);
		form.append(si1);
		form.append(si2);
		form.append(si3);

		ImageItem ii1 = new ImageItem(null, img, ImageItem.LAYOUT_CENTER, "Taobao", ImageItem.BUTTON);
		ii1.addCommand(new Command("IMG", Command.OK, 0));
		ii1.setItemCommandListener(this);
		form.append(ii1);

		TextField tf1 = new TextField("site", "http://www.senseforce.com", 30, TextField.ANY);
		form.append(tf1);

                myCheck = new MyCheckItem("Gender", "/male.png", "/female.png");
                form.append(myCheck);

		display.setCurrent(form);
	}

	public void commandAction(Command c, Displayable s) {
//		if (c == List.SELECT_COMMAND) {
//			List list = (List)s;
//			System.out.println("You selecting the "+list.getSelectedIndex()+"th:"+list.getString(list.getSelectedIndex()));
//		}
//		else {
//			String cmd = c.getLabel();
//			if (cmd.equals("OK")) {
//				List list = (List)s;
//				System.out.println("You verified the "+list.getSelectedIndex()+"th:"+list.getString(list.getSelectedIndex()));
//			}
//		}

	}

	public void commandAction(Command arg0, Item arg1) {
		// TODO Auto-generated method stub

	}
}
